/*
 * Jenny Ruppen 09-730-391
 * Sebastien Goldberg 08-914-855
 * Henry Raymond 08-928-061
 * Stefan Mussato 09-752-270
 */
 
package ch.uzh.ifi.sopra.gruppe9.game;

import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.math.ColorRGBA;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapMode;


/**
 * Manages all jME3 Materials.
 */
public class MaterialManager {
	
	
	/**
	 * Asset Manager of jME3
	 */
	private static AssetManager assetManager;
	
	
	/**
	 * Background marble texture.
	 */
	private static Material marble;
	
	
	/**
	 * Logo texture.
	 */
	private static Material logo;
	
	
	/**
	 * Button texture.
	 */
	private static Material button;
	
	
	/**
	 * Text input field.
	 */
	private static Material textInput;
	
	
	/**
	 * Solid black.
	 */
	private static Material black;
	
	
	/**
	 * Waiting wheel spoke.
	 */
	private static Material waiting;
	
	
	/**
	 * GUI Box outline.
	 */
	private static Material guiBox;
	
	
	/**
	 * Very light grey shade.
	 */
	private static Material shade;
	
	
	/**
	 * Little squares will player color.
	 */
	private static Material playerColors;
	
	
	/**
	 * GUI window frame.
	 */
	private static Material window;
	
	
	/**
	 * GUI selection option button.
	 */
	private static Material selectionOption;
	
	
	/**
	 * Logo on the top of the in-game panel.
	 */
	private static Material panelLogo;
	
	
	/**
	 * Season icon of the in-game panel.
	 */
	private static Material seasons;
	
	
	/**
	 * Icons of the in-game panel.
	 */
	private static Material panelIcons;
	
	
	/**
	 * Slot box texture.
	 */
	private static Material slot;
	
	
	/**
	 * Blue buying agent.
	 */
	private static Material blueBuyingAgent;
	
	
	/**
	 * Green buying agent.
	 */
	private static Material greenBuyingAgent;
	
	
	/**
	 * Yellow buying agent.
	 */
	private static Material yellowBuyingAgent;
	
	
	/**
	 * Purple buying agent.
	 */
	private static Material purpleBuyingAgent;
	
	
	/**
	 * Orange buying agent.
	 */
	private static Material orangeBuyingAgent;
	
	
	/**
	 * Two buying agents.
	 */
	private static Material twoBuyingAgents;
	
	
	/**
	 * Bank building texture.
	 */
	private static Material bank;
	
	
	/**
	 * Construction authority building texture.
	 */
	private static Material constructionAuthority;
	
	
	/**
	 * Tower element market building texture.
	 */
	private static Material towerElementMarket;
	
	
	/**
	 * House of spies building texture.
	 */
	private static Material houseOfSpies;
	
	
	/**
	 * Palace of the caliph building texture.
	 */
	private static Material palaceOfTheCaliph;
	
	
	/**
	 * Color constraint flags.
	 */
	private static Material colorConstraintFlags;
	
	
	/**
	 * Icons of the money selection in the bank.
	 */
	private static Material bankIcons;
	
	
	/**
	 * Icons of the number of buying agents the player wants to use for an action.
	 */
	private static Material buyingAgentIcons;
	
	
	/**
	 * Icons of the house of spies from which the player can choose which market he wants to bribe.
	 */
	private static Material bribingIcons;
	
	
	/**
	 * Icons of the construction authority from which the player can choose how many tower elements he wants to build.
	 */
	private static Material constructionIcons;
	
	
	/**
	 * Texture of brown tower elements.
	 */
	private static Material brownTower;
	
	
	/**
	 * Texture of green tower elements.
	 */
	private static Material greenTower;
	
	
	/**
	 * Texture of red tower elements.
	 */
	private static Material redTower;
	
	
	/**
	 * Texture of black tower elements.
	 */
	private static Material blackTower;
	
	
	/**
	 * Texture of white tower elements.
	 */
	private static Material whiteTower;
	
	
	/**
	 * Texture of tabs box.
	 */
	private static Material tabsBox;
	
	
	/**
	 * Texture of single tab button.
	 */
	private static Material tabButton;
	
	
	/**
	 * Texture of the sky of the scenery.
	 */
	private static Material sky;
	
	
	/**
	 * Texture of the arrows showing the player where he can add tower elements in existing towers.
	 */
	private static Material arrow;
	
	
	/**
	 * Loads all textures.
	 */
	public static void loadAll(AssetManager newAssetManager) {
		assetManager = newAssetManager;
		
		marble = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        marble.setColor("Color", ColorRGBA.White);
        Texture marbleTexture = assetManager.loadTexture("assets/Textures/General/marble.png");
        marbleTexture.setWrap(WrapMode.Repeat);
        marble.setTexture("ColorMap", marbleTexture);
        
		logo = createAlphaBlendedMaterial("assets/Textures/General/logo.png");
        
        button = createAlphaBlendedMaterial("assets/Textures/General/button.png");
        
        textInput = createAlphaBlendedMaterial("assets/Textures/General/input.png");
        
        waiting = createAlphaBlendedMaterial("assets/Textures/General/waiting.png");
        
        black = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        black.setColor("Color", ColorRGBA.Black);
        
        guiBox = createAlphaBlendedMaterial("assets/Textures/General/box.png");
        
        shade = createAlphaBlendedMaterial("assets/Textures/General/shade.png");
        
        playerColors = createAlphaBlendedMaterial("assets/Textures/General/colors.png");
        
        window = createAlphaBlendedMaterial("assets/Textures/General/window.png");
        
        selectionOption = createAlphaBlendedMaterial("assets/Textures/General/option.png");
        
        panelLogo = createAlphaBlendedMaterial("assets/Textures/Panel/logo.png");
        
        seasons = createAlphaBlendedMaterial("assets/Textures/Panel/seasons.png");
        
        panelIcons = createAlphaBlendedMaterial("assets/Textures/Panel/icons.png");
        
        slot = createAlphaBlendedMaterial("assets/Textures/General/slot.png");
        
        blueBuyingAgent = createAlphaBlendedMaterial("assets/Textures/BuyingAgents/blue.png");
        
        greenBuyingAgent = createAlphaBlendedMaterial("assets/Textures/BuyingAgents/green.png");
        
        yellowBuyingAgent = createAlphaBlendedMaterial("assets/Textures/BuyingAgents/yellow.png");
        
        purpleBuyingAgent = createAlphaBlendedMaterial("assets/Textures/BuyingAgents/purple.png");
        
        orangeBuyingAgent = createAlphaBlendedMaterial("assets/Textures/BuyingAgents/orange.png");
        
        twoBuyingAgents = createAlphaBlendedMaterial("assets/Textures/BuyingAgents/two.png");
        
        bank = createAlphaBlendedMaterial("assets/Textures/Buildings/bank.png");
        
        constructionAuthority = createAlphaBlendedMaterial("assets/Textures/Buildings/construction_authority.png");
        
        towerElementMarket = createAlphaBlendedMaterial("assets/Textures/Buildings/tower_element_market.png");
        
        houseOfSpies = createAlphaBlendedMaterial("assets/Textures/Buildings/house_of_spies.png");
        
        palaceOfTheCaliph = createAlphaBlendedMaterial("assets/Textures/Buildings/palace_of_the_caliph.png");

        colorConstraintFlags = createAlphaBlendedMaterial("assets/Textures/Buildings/flags.png");
        
        bankIcons = createAlphaBlendedMaterial("assets/Textures/Buildings/bank_icons.png");
        
        buyingAgentIcons = createAlphaBlendedMaterial("assets/Textures/BuyingAgents/icons.png");
        
        bribingIcons = createAlphaBlendedMaterial("assets/Textures/Buildings/bribing.png");
        
        constructionIcons = createAlphaBlendedMaterial("assets/Textures/Buildings/construction_icons.png");
        
        brownTower = createAlphaBlendedMaterial("assets/Textures/Towers/brown.png");
        
        greenTower = createAlphaBlendedMaterial("assets/Textures/Towers/green.png");
        
        redTower = createAlphaBlendedMaterial("assets/Textures/Towers/red.png");
        
        blackTower = createAlphaBlendedMaterial("assets/Textures/Towers/black.png");
        
        whiteTower = createAlphaBlendedMaterial("assets/Textures/Towers/white.png");

        tabsBox = createAlphaBlendedMaterial("assets/Textures/Buildings/tabs.png");
        
        tabButton = createAlphaBlendedMaterial("assets/Textures/Buildings/tab_button.png");
        
        sky = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        sky.setColor("Color", ColorRGBA.White);
        sky.setTexture("ColorMap", assetManager.loadTexture("assets/Textures/Scenery/sky.png"));
        
        arrow = createAlphaBlendedMaterial("assets/Textures/General/arrow.png");
	}


	private static Material createAlphaBlendedMaterial(String texturePath) {
		 Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
		 material.setColor("Color", ColorRGBA.White);
		 material.setTexture("ColorMap", assetManager.loadTexture(texturePath));
		 material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
		 return material;
	}


	public static Material getMarble() {
		return marble;
	}
	
	public static Material getLogo() {
		return logo;
	}
	
	public static Material getButton() {
		return button;
	}
	
	public static Material getTextInput() {
		return textInput;
	}
	
	public static Material getBlack() {
		return black;
	}
	
	public static Material getWaiting() {
		return waiting;
	}
	
	public static Material getGuiBox() {
		return guiBox;
	}
	
	public static Material getShade() {
		return shade;
	}
	
	public static Material getPlayerColors() {
		return playerColors;
	}
	
	public static Material getWindow() {
		return window;
	}
	
	public static Material getSelectionOption() {
		return selectionOption;
	}
	
	public static Material getPanelLogo() {
		return panelLogo;
	}
	
	public static Material getSeasons() {
		return seasons;
	}
	
	public static Material getPanelIcons() {
		return panelIcons;
	}
	
	public static Material getSlot() {
		return slot;
	}

	public static Material getBlueBuyingAgent() {
		return blueBuyingAgent;
	}

	public static Material getGreenBuyingAgent() {
		return greenBuyingAgent;
	}

	public static Material getYellowBuyingAgent() {
		return yellowBuyingAgent;
	}

	public static Material getPurpleBuyingAgent() {
		return purpleBuyingAgent;
	}

	public static Material getOrangeBuyingAgent() {
		return orangeBuyingAgent;
	}
	
	public static Material getTwoBuyingAgents() {
		return twoBuyingAgents;
	}

	public static Material getBank() {
		return bank;
	}

	public static Material getConstructionAuthority() {
		return constructionAuthority;
	}

	public static Material getTowerElementMarket() {
		return towerElementMarket;
	}

	public static Material getHouseOfSpies() {
		return houseOfSpies;
	}

	public static Material getPalaceOfTheCaliph() {
		return palaceOfTheCaliph;
	}
	
	public static Material getColorConstraintFlags() {
		return colorConstraintFlags;
	}
	
	public static Material getBankIcons() {
		return bankIcons;
	}
	
	public static Material getBuyingAgentIcons() {
		return buyingAgentIcons;
	}
	
	public static Material getBribingIcons() {
		return bribingIcons;
	}
	
	public static Material getConstructionIcons() {
		return constructionIcons;
	}
	
	public static Material getBrownTower() {
		return brownTower;
	}

	public static Material getGreenTower() {
		return greenTower;
	}

	public static Material getRedTower() {
		return redTower;
	}

	public static Material getBlackTower() {
		return blackTower;
	}

	public static Material getWhiteTower() {
		return whiteTower;
	}

	public static Material getTabsBox() {
		return tabsBox;
	}

	public static Material getTabButton() {
		return tabButton;
	}
	
	public static Material getSky() {
		return sky;
	}
	
	public static Material getArrow() {
		return arrow;
	}
	
}
